#include <iostream>
#include <unistd.h>
#include "thread.hpp" 

using namespace ThreadMoudle;
int tickets=1000;
void route(const std::string &name)
{
    while(true)
    {
        if(tickets>0)
        {
            usleep(1000);
            printf("who: %s,get a ticket:%d\n",name.c_str(),tickets); //char*类型，name是std::string类型，所以要转换类型
            tickets--;
        }
        else{
            break;
        }
    }
}
int main()
{
    //会出现ticket为负数的情况，下一篇引入锁来解决。
    Thread s1("thread-1",route);
    Thread s2("thread-2",route);
    Thread s3("thread-3",route);
    Thread s4("thread-4",route);
    Thread s5("thread-5",route);

    s1.start();
    s2.start();
    s3.start();
    s4.start();
    s5.start();

    s1.join();
    s2.join();
    s3.join();
    s4.join();
    s5.join();
}

